#include "CardType.h"
#include "CardTypeData.h"
#include "CardType.h"
#include <iostream>
#include "CardTypeManager.h"

FullHouse::FullHouse() {
}

FullHouse::~FullHouse() {
}

CardTypeData FullHouse::getCardType(const PokerData & data) const{
  vector<Poker> pokers = data.getPokers();
  int count = pokers.size();
  bool three = false;
  int value = 0;
  if (count > 4) {
    PokerData::sortData(pokers);
    for (int i = 0; i < count - 2; i++) {
      if (pokers.at(i).value == pokers.at(i+2).value) {
        three = true;
        value = pokers.at(i).value;
        break;
      }
    }
    if (three) {
      for (int i = 0; i < count - 1; i++) {
        const Poker & p = pokers.at(i);
        if (p.value != value && p.value == pokers.at(i + 1).value) {
          CardTypeData cardTypeData;
          cardTypeData.type = CardType::FullHouse;
          cardTypeData.first = value;
          cardTypeData.second = p.value;
          return cardTypeData;
        }
      }
    }
  }
  return getNextType()->getCardType(data);
}

const CardType * FullHouse::getNextType() const {
  return CardTypeManager::sharedCardTypeManager()->getCardType(CardType::Flush);
}
